#include "optiondialog.h"
#include "ui_optiondialog.h"
#include <QDateTime>
#include <QTimer>
#include "settings/parametersettings.h"
#include "settings/calibrationwidget.h"
#include "settings/IOSettings/iosettingwidget.h"
#include "settings/IOSettings/iofunctiontest.h"
#include "common/common.h"
#include <QApplication>
#include "settings/systemsettingwidget.h"
#include "RecordWidget/recordwidget.h"

OptionDialog::OptionDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::OptionDialog)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint);
    this->setWindowState(Qt::WindowMaximized);
    this->setAttribute(Qt::WA_DeleteOnClose);
    ui->lab_date->setText(QDate::currentDate().toString("yyyy-MM-dd"));
    ui->lab_time->setText(QTime::currentTime().toString("hh:mm:ss"));
    mtimer = new QTimer(this);
    connect(mtimer,SIGNAL(timeout()),this,SLOT(displayTime()));
    mtimer->start(1000);
}

OptionDialog::~OptionDialog()
{
    delete mtimer;
    delete ui;
}

void OptionDialog::on_btn_main_clicked()
{
    this->accept();
}

void OptionDialog::on_btn_wgtSetting_clicked()
{
    //beep1;
    ParameterSettings* w = new ParameterSettings();
    w->show();
}

void OptionDialog::displayTime()
{
    ui->lab_date->setText(QDate::currentDate().toString("yyyy-MM-dd"));
    ui->lab_time->setText(platform_sys_info_c::get_rtc_time().time().toString("hh:mm:ss"));
}

//void OptionDialog::on_btn_calibrate_clicked()
//{
//    beep1;
//    CalibrationWidget* w = new CalibrationWidget();
//    w->show();
//}

void OptionDialog::on_btn_IO_clicked()
{
    IOSettingWidget* IO = new IOSettingWidget();
    IO->show();
}

void OptionDialog::on_btn_iotest_clicked()
{
    IOFunctionTest* iotest = new IOFunctionTest();
    iotest->show();
}

void OptionDialog::on_btn_poweroff_clicked()
{
#ifdef PC_DEVICE
    qApp->exit(0);
#else
    DoSystem("poweroff");
#endif
}

void OptionDialog::on_btn_reboot_clicked()
{
    DoSystem("reboot");
}

//void OptionDialog::on_btn_sysSetting_clicked()
//{
//    beep1;
//    SystemSettingWidget* w = new SystemSettingWidget();
//    w->show();
//}

void OptionDialog::on_btn_record_clicked()
{
    RecordWidget* w = new RecordWidget();
    w->show();
}
